package com.atguigu.b_equals;

import java.util.Scanner;

/*
    模拟用户登录
 */
public class Test {
    public static void main(String[] args) {
        //模拟数据库
        String username = "admin";
        String password = "123456";
        String checkWord = "U7Y5"; //功能: 自动生成

        //模拟用户登录
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请您输入账号 : ");
            String uName = sc.nextLine();
            System.out.println("请您输入密码 : ");
            String pwd = sc.nextLine();
            System.out.println("请您输入验证码 : " + checkWord);
            String cWord = sc.nextLine();

            //校验
            if (username.equals(uName) && password.equals(pwd) && checkWord.equalsIgnoreCase(cWord)){
                System.out.println("恭喜您,登录成功 ! ");
                return;
            }else {
                //登录失败且是第三次登录
                if (i == 2){
                    System.out.println("您已经连续三次登录失败 ! 账号被锁定,请联系管理员 ! ");
                    return;
                }
                System.out.println("登录失败 ! 您还剩 " + (2 - i) + " 次机会尝试 ! ");
            }
        }
    }
}
